home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 3.iso / dist / fw_mysql.idb / usr / freeware / share / sql-bench / run-all-tests.z / run-all-tests
Text File  |  2002-10-07  |  7KB  |  299 lines

  1. #!/usr/sbin/perl
  2. # Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
  3. #
  4. # This library is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Library General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2 of the License, or (at your option) any later version.
  8. #
  9. # This library is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. # Library General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Library General Public
  15. # License along with this library; if not, write to the Free
  16. # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
  17. # MA 02111-1307, USA
  18. #
  19. # This program runs all test that starts with 'test-' and sums
  20. # the results that the program prints.
  21. # Each time result should be of the form:
  22. # Time for|to KEYWORD (number_of_runs) 'other info': timestr()
  23. #
  24. # All options to this script is passed to all test program.
  25. # useful options:
  26. # --fast --force --lock-tables
  27. # --server   ==> mysql (default) / mSQL / Pg (postgres) / Solid
  28. # --user     ==> the user with permission to create / drop / select
  29. # --pass     ==> password for the user
  30. # --cmp      ==> Compare --server with one of the others (mysql/mSQL/Pg/Solid)
  31. # --comments ==> everything you want to say such as the extra options you
  32. #                gave to the db server. (use --comments="xxx xxx xxx"
  33. # --machine  ==> Give a OS/machine id for your logfiles.
  34. # --log         ==> puts output in output/RUN-server-machine-cmp-$opt_cmp
  35.  
  36. use DBI;
  37.  
  38. $opt_silent=1;            # Don't write header
  39.  
  40. @ORG_ARGV=@ARGV;
  41. chomp($pwd = `pwd`); $pwd = "." if ($pwd eq '');
  42. require "$pwd/bench-init.pl" || die "Can't read Configuration file: $!\n";
  43. $opt_silent=0;
  44. $perl=$^X;
  45. $machine=machine();
  46. $redirect= !($machine =~ /windows/i || $machine =~ "^NT\s") ? "2>&1" : "";
  47. $dir= ($pwd =~ /\\/) ? '\\' : '/';    # directory symbol for shell
  48.  
  49. $prog_args="";
  50. foreach $arg (@ORG_ARGV)
  51. {
  52.   if ($redirect)
  53.   {
  54.     $prog_args.="'" . $arg . "' ";
  55.   }
  56.   else
  57.   {
  58.     # Windows/NT can't handle ' around arguments
  59.     $prog_args.=$arg . " ";    
  60.   }
  61. }
  62.  
  63. $prog_count=$errors=0;
  64.  
  65. if ($opt_cmp) {
  66.     $filename = "$opt_server$opt_suffix-" . machine_part() . "-cmp-$opt_cmp";
  67. } else {
  68.     $filename = "$opt_server$opt_suffix-" . machine_part();
  69. }
  70.  
  71. if (! -d $opt_dir)
  72. {
  73.   if (-e $opt_dir)
  74.   {
  75.     die "$opt_dir isn't a directory\n";
  76.   }
  77.   mkdir $opt_dir,0777 || die "Can't create directory: $opt_dir\n";
  78. }
  79.  
  80. if ($opt_skip_test) {
  81.   (@skip_tests) = split(/,\s*/, $opt_skip_test);
  82. }
  83.  
  84. if ($opt_old_headers)
  85. {
  86.   read_headers("$opt_dir/RUN-$filename");
  87. }
  88. else
  89. {
  90.   $server_version=$server->version();
  91. }
  92.  
  93. if (!$opt_log)
  94. {
  95.   open(LOG,">&STDOUT");
  96. }
  97. else
  98. {
  99.   open(LOG, "> $opt_dir/RUN-$filename") ||
  100.     die "Can't write to $opt_dir/RUN-$filename: $!\n";
  101. }
  102.  
  103. select(LOG);
  104. $|=1;
  105.  
  106. print "Benchmark DBD suite: $benchmark_version\n";
  107. print "Date of test:        $date\n";
  108. print "Running tests on:    $machine\n";
  109. print "Arguments:           $log_prog_args\n";
  110. print "Comments:            $opt_comments\n";
  111. print "Limits from:         $opt_cmp\n";
  112. print "Server version:      $server_version\n\n";
  113.  
  114.  
  115. $estimated=$warning=$got_warning=0;
  116. while (<test-*>)
  117. {
  118.   next if (/\.sh$/);        # configure script
  119.   next if (/\-fork$/);        # test script
  120.   $prog_count++;
  121.   /test-(.*)$/;            # Remove test from name
  122.   $prog=$1;
  123.   $skip_prog = 0;
  124.   foreach $skip_this (@skip_tests) {
  125.     if ($prog =~ /$skip_this/i) {
  126.       $skip_prog = 1;
  127.       last;
  128.     }
  129.   }
  130.   print "$prog: ";
  131.   if ((!$opt_use_old_results) && (!$skip_prog))
  132.   {
  133.     if (system("$perl ./test-$prog $prog_args > \"$opt_dir$dir$prog-$filename\" $redirect"))
  134.     {
  135.       printf STDERR "Warning: Can't execute $prog.  Check the file '$opt_dir$dir$prog-$filename'\n";
  136.       die "aborted" if ($opt_die_on_errors);
  137.     }
  138.   }
  139.   open(TEST,"$opt_dir/$prog-$filename");
  140.   $last_line="";
  141.   while(<TEST>)
  142.   {
  143.     chomp;
  144.     $last_line=$_ if (!(/^\s*$/));        # Search after last line
  145.   }
  146.   if ($last_line =~ /Total time:/i)
  147.   {
  148.     print $last_line . "\n";
  149.     open(TEST,"$opt_dir/$prog-$filename");
  150.     while (<TEST>)
  151.     {
  152.       if (/^(estimated |)time (to|for) ([^\s:]*)\s*\((\d*)(:\d*)*\)[^:]*:\s*([\d.]+) .*secs \(\s*([^\s]*) usr\s*\+*\s*([^\s]*) sys.*=\s+([\d.]*)\s+cpu/i)
  153.       {
  154.     $arg=$summa{$3};
  155.     if (!defined($arg))
  156.     {
  157.       $summa{$3}= [ $4,$6,$7,$8,$9,""];
  158.     }
  159.     else
  160.     {
  161.       $arg->[0]+=$4;
  162.       $arg->[1]+=$6;
  163.       $arg->[2]+=$7;
  164.       $arg->[3]+=$8;
  165.       $arg->[4]+=$9;
  166.     }
  167.     $prog_sum[0]+=$4;
  168.     $prog_sum[1]+=$6;
  169.     $prog_sum[2]+=$7;
  170.     $prog_sum[3]+=$8;
  171.     $prog_sum[4]+=$9;
  172.     if (length($1))
  173.     {
  174.       $summa{$3}->[5].="+";
  175.       $estimated=1;
  176.     }
  177.     if ($got_warning)
  178.     {
  179.       $summa{$3}->[5].="?";
  180.       $warning=1;
  181.       $got_warning=0;
  182.     }
  183.       }
  184.       elsif (/^warning/i)
  185.       {
  186.     $got_warning=1;
  187.       }
  188.       else
  189.       {
  190.     $got_warning=0;
  191.       }
  192.     }
  193.     if ($opt_debug)
  194.     {
  195.       print "Summary for $prog: ", join(" ",@prog_sum), "\n";
  196.     }
  197.   }
  198.   else
  199.   {
  200.     $errors++;
  201.     print "Failed ($opt_dir/$prog-$filename)\n";
  202.   }
  203. }
  204.  
  205. print "\n";
  206. if (!$errors)
  207. {
  208.   print "All $prog_count test executed successfully\n";
  209. }
  210. else
  211. {
  212.   print "Of $prog_count tests, $errors tests didn't work\n";
  213. }
  214. if ($estimated)
  215. {
  216.   print "Tests with estimated time have a + at end of line\n"
  217. }
  218. if ($warning)
  219. {
  220.   print "Tests with didn't return the correct result have a ? at end of line\n";
  221. }
  222.  
  223. if (%summa)
  224. {
  225.   @total=(0,0,0,0,0,"");
  226.   print "\nTotals per operation:\n";
  227.   print "Operation             seconds     usr     sys     cpu   tests\n";
  228.   foreach $key (sort(keys %summa))
  229.   {
  230.     $arg=$summa{$key};
  231.     printf("%-35.35s %7.2f %7.2f %7.2f %7.2f %7d %s\n",
  232.        $key,$arg->[1],$arg->[2],$arg->[3],$arg->[4],$arg->[0],
  233.        $arg->[5]);
  234.  
  235.     for ($i=0 ; $i < 5 ; $i++)
  236.     {
  237.       $total[$i]+=$arg->[$i];
  238.     }
  239.     $total[5].=$arg->[$i];
  240.   }
  241.   printf("%-35.35s %7.2f %7.2f %7.2f %7.2f %7d %s\n",
  242.      "TOTALS",$total[1],$total[2],$total[3],$total[4],$total[0],
  243.      $total[5]);
  244. }
  245.  
  246. select(STDOUT);
  247. if ($opt_log)
  248. {
  249.   print "Test finished. You can find the result in:\n$opt_dir/RUN-$filename\n";
  250. }
  251.  
  252.  
  253. #
  254. # Read headers from an old benchmark run
  255. #
  256.  
  257. sub read_headers
  258. {
  259.   my ($filename)=@_;
  260.  
  261.   # Clear current values
  262.   $benchmark_version=$date=$machine=$server_version="";
  263.  
  264.   open(TMP, "<$filename") || die "Can't open $filename\n";
  265.   while (<TMP>)
  266.   {
  267.     chop;
  268.     if (/^Benchmark DBD.*:\s+(.*)$/)
  269.     {
  270.       $benchmark_version=$1;
  271.     }
  272.     elsif (/^Date of.*:\s+(.*)/)
  273.     {
  274.       $date=$1;
  275.     }
  276.     elsif (/^Running.*:\s+(.*)$/)
  277.     {
  278.       $machine=$1;
  279.     }
  280.     elsif (/^Arguments.*:\s+(.*)$/)
  281.     {
  282.       $log_prog_args=$1;
  283.     }
  284.     elsif (/^Comments.*:\s+(.*)$/)
  285.     {
  286.       $opt_comments=$1;
  287.     }
  288.     elsif (/^Limits.*:\s+(.*)$/)
  289.     {
  290.       $opt_cmp=$1;
  291.     }
  292.     elsif (/^Server ver.*:\s+(.*)$/)
  293.     {
  294.       $server_version=$1;
  295.     }
  296.   }
  297.   close(TMP);
  298. }
  299.